function postManager(actionindex, tid, postid){
	var actions=["",			"delPost",	"movePost",	"coverPost",	"lockPost",		"topPost",		"alltopPost",	"goodPost",	"onoffPost",	"upPost",	"stampPost",	"highlightPost"];
	var action=actions[actionindex];
	switch(action){
		case "delPost":
			popwin.showURL('删除帖子','postmanager.php?action='+action+'&tid='+tid+'&postid='+postid, 420, 250);	
		break;
		case "movePost":
			popwin.showURL('移动帖子','postmanager.php?action='+action+'&tid='+tid+'&postid='+postid, 420, 250);	
		break;
		case "coverPost":
			popwin.showURL('屏蔽帖子','postmanager.php?action='+action+'&tid='+tid+'&postid='+postid, 420, 250);	
		break;
		case "lockPost":
			popwin.showURL('锁定帖子','postmanager.php?action='+action+'&tid='+tid+'&postid='+postid, 420, 250);	
		break;
		case "topPost":
			popwin.showURL('置顶帖子','postmanager.php?action='+action+'&tid='+tid+'&postid='+postid, 420, 250);	
		break;
		case "alltopPost":
			popwin.showURL('总置顶','postmanager.php?action='+action+'&tid='+tid+'&postid='+postid, 420, 250);	
		break;
		case "goodPost":
			popwin.showURL('精华帖子','postmanager.php?action='+action+'&tid='+tid+'&postid='+postid, 420, 250);	
		break;
		case "upPost":
			popwin.showURL('提升帖子','postmanager.php?action='+action+'&tid='+tid+'&postid='+postid, 420, 250);	
		break;
		case "stampPost":
			popwin.showURL('鉴定帖子','postmanager.php?action='+action+'&tid='+tid+'&postid='+postid, 420, 250);	
		break;
		case "highlightPost":
			popwin.showURL('高亮显示','postmanager.php?action='+action+'&tid='+tid+'&postid='+postid, 420, 250);	
		break;
		
	}
}

function delPost(){
	popwin.loading();
	ajaxPost("postform","ajaxadmin.php?action=delPost", delPost_callback);
}
function delPost_callback(data){
	var btns=[{value:" 确 定 ",onclick:"popwin.close();self.location.reload();",focus:true}];
	popwin.loaded();
	if(data=="y"){
		popwin.showDialog(1,"删除成功","帖子删除成功",btns,280,130);
	}else{
		popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
	}
}
	
function movePost(){
	popwin.loading();
	ajaxPost("postform","ajaxadmin.php?action=movePost", movePost_callback);
}
function movePost_callback(data){
	var btns=[{value:" 确 定 ",onclick:"popwin.close();self.location.reload();",focus:true}];
	popwin.loaded();
	if(data=="y"){
		popwin.showDialog(1,"移动成功","帖子移动成功",btns,280,130);
	}else{
		popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
	}
}
	
	
function coverPost(){
	popwin.loading();
	ajaxPost("postform","ajaxadmin.php?action=coverPost", coverPost_callback);
}
function coverPost_callback(data){
	var btns=[{value:" 确 定 ",onclick:"popwin.close();self.location.reload();",focus:true}];
	popwin.loaded();
	if(data=="y"){
		popwin.showDialog(1,"屏蔽成功","帖子屏蔽成功",btns,280,130);
	}else{
		popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
	}
}

function lockPost(){
	popwin.loading();
	ajaxPost("postform","ajaxadmin.php?action=lockPost", lockPost_callback);
}
function lockPost_callback(data){
	var btns=[{value:" 确 定 ",onclick:"popwin.close();self.location.reload();",focus:true}];
	popwin.loaded();
	if(data=="y"){
		popwin.showDialog(1,"锁帖成功","帖子锁定成功",btns,280,130);
	}else{
		popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
	}
}
	
function topPost(){
	popwin.loading();
	ajaxPost("postform","ajaxadmin.php?action=topPost", topPost_callback);
}
function topPost_callback(data){
	var btns=[{value:" 确 定 ",onclick:"popwin.close();self.location.reload();",focus:true}];
	popwin.loaded();
	if(data=="y"){
		popwin.showDialog(1,"置顶成功","帖子置顶成功",btns,280,130);
	}else{
		popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
	}
}
	
	
function alltopPost(){
	popwin.loading();
	ajaxPost("postform","ajaxadmin.php?action=alltopPost", alltopPost_callback);
}
function alltopPost_callback(data){
	var btns=[{value:" 确 定 ",onclick:"popwin.close();self.location.reload();",focus:true}];
	popwin.loaded();
	if(data=="y"){
		popwin.showDialog(1,"置顶成功","帖子总置顶成功",btns,280,130);
	}else{
		popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
	}
}	

	
	
function goodPost(){
	popwin.loading();
	ajaxPost("postform","ajaxadmin.php?action=goodPost", goodPost_callback);
}
function goodPost_callback(data){
	var btns=[{value:" 确 定 ",onclick:"popwin.close();self.location.reload();",focus:true}];
	popwin.loaded();
	if(data=="y"){
		popwin.showDialog(1,"设定精华帖子","帖子设定精华成功",btns,280,130);
	}else{
		popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
	}
}

function upPost(){
	popwin.loading();
	ajaxPost("postform","ajaxadmin.php?action=upPost", upPost_callback);
}
function upPost_callback(data){
	var btns=[{value:" 确 定 ",onclick:"popwin.close();self.location.reload();",focus:true}];
	popwin.loaded();
	if(data=="y"){
		popwin.showDialog(1,"提升成功","帖子提升成功",btns,280,130);
	}else{
		popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
	}
}


function stampPost(){
	popwin.loading();
	ajaxPost("postform","ajaxadmin.php?action=stampPost", stampPost_callback);
}
function stampPost_callback(data){
	var btns=[{value:" 确 定 ",onclick:"popwin.close();self.location.reload();",focus:true}];
	popwin.loaded();
	if(data=="y"){
		popwin.showDialog(1,"鉴定成功","帖子鉴定成功",btns,280,130);
	}else{
		popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
	}
}
function highlightPost(){
	popwin.loading();
	ajaxPost("postform","ajaxadmin.php?action=highlightPost", highlightPost_callback);
}
function highlightPost_callback(data){
	var btns=[{value:" 确 定 ",onclick:"popwin.close();",focus:true}];
	popwin.loaded();
	if(data=="y"){
		popwin.showDialog(1,"鉴定成功","帖子高亮选项设置成功",btns,280,130);
	}else{
		popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
	}
}

function postVote(tid){
	ajaxPost("voteform","ajaxmember.php?action=postVote&tid="+tid,postVote_callback);
}

function postVote_callback(data){
	popwin.loaded();
	if(data=="y"){
		var btns=[{value:" 确 定 ",onclick:"popwin.close();self.location.reload();",focus:true}];
		popwin.showDialog(1,"投票成功","投票成功",btns,280,130);
	}else{
		var btns=[{value:" 确 定 ",onclick:"popwin.close();",focus:true}];
		popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
	}	
}

function viewVoter(tid){
	popwin.showURL('查看投票参与者','viewvote.php?action=view&tid='+tid, 450, 450);
}

function setBestAnswer(tid, postid){
	var btns=[
		{value:" 确 认 ",onclick:"ajax_setBestAnswer("+tid+","+postid+")",focus:true},
		{value:" 取 消 ",onclick:"popwin.close()"}
	];
	popwin.showDialog(2,"确认","您确认设定该回复为最佳答案吗？您的悬赏积分将会作为该作者的奖励。<br />是否确认继续？",btns,320,130);
}

function ajax_setBestAnswer(tid, postid){
	popwin.loading();
	ajaxGet("ajaxmember.php?action=setBestAnswer&tid="+tid+"&postid="+postid, _setBestAnswer_callback);
}
function _setBestAnswer_callback(data){
	var btns=[{value:" 确 定 ",onclick:"popwin.close();self.location.reload();",focus:true}];
	popwin.loaded();
	if(data=="y"){
		popwin.showDialog(1,"设定成功","成功设定最佳答案。",btns,280,130);
	}else{
		popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
	}
}


//发布帖子
var hasErr = false;
var hasVerifyCallback=false;

var voteNum=0;
function addVoteItem(){
	var items=document.getElementsByName('voteitem[]');
	if(items.length>=10){
		return;
	}
	var s="<div class=post_voteitem><input type='text' style='width:400px;' name='voteitem[]' tabindex='100"+voteNum+"' class='text_css' /> <a href=\"javascript:delVoteItem("+voteNum+")\" title=\"删除选项\">X</a></div>";
	var ele=document.createElement('div');
	ele.id="vote_"+voteNum;
	ele.innerHTML=s;
	E("votesdiv").appendChild(ele);
	voteNum++;
	
}
function delVoteItem(index){
	E("vote_"+index+"").innerHTML ="";
}


function checkTitle(){
	var v = E("title").value;
	if(v==""||getLength(v)<2||getLength(v)>64){
		hasErr = true;
		var btns=[{value:" 确 定 ",onclick:"popwin.close();E('title').focus();",focus:true}];
		popwin.showDialog(2,"标题错误","标题的长度必须在2~64个字节。",btns,320,130);
	}else{
		
	}
}

function checkContent(hasreturn){
	Editor.attachSubmit();
	var v = E("content").value;
	if(v==""||getLength(v)<10||getLength(v)>10000){
		hasErr = true;
		var btns=[{value:" 确 定 ",onclick:"popwin.close();",focus:true}];
		popwin.showDialog(2,"内容错误","内容的长度必须在10~10000个字节。",btns,320,130);
		if(hasreturn){return false;}
	}else{
		if(hasreturn){return true;}
	}
}

function checkVotetime(){
	var v1 = E("starttime").value;
	var v2 = E("stoptime").value;
	if(v1==""||v2==""){
		hasErr = true;
		var btns=[{value:" 确 定 ",onclick:"popwin.close();E('starttime').focus();",focus:true}];
		popwin.showDialog(2,"时间错误","请填写“允许投票时间段”。",btns,320,130);
	}else{
		
	}
}

function checkSecurityCode(){
	var v = trim(E("securitycode").value);
	E("verify_tips").innerHTML = "<span class='checkingStyle'>正在检测...</span>";
	hasVerifyCallback=false;
	ajaxGet("ajaxpublic.php?action=checkSecurityCode&v="+urlEncode(v)+"&t="+getTimer(), checkSecurityCode_callback);
}

function checkSecurityCode_callback(data){
	if(data=="y"){
		E("verify_tips").innerHTML = "<span class='yesStyle'>填写正确</span>";
	}else{
		hasErr = true;
		E("verify_tips").innerHTML = "<span class='errStyle'>"+data+"</span>";
	}
	hasVerifyCallback=true;
}

function checkAllAction(){
	hasErr=false;
	checkTitle();
	if(hasErr)return false;
	checkContent();
	if(hasErr)return false;
	if(topictype==1){
		checkVotetime();
	}
	if(hasErr)return false;
	return true;
}

//必须实现该方法，点击UBB编辑器的时候触发的事件。
function openUploadAttach(){
	if(popedom_14=="0"){
		var btns=[{value:" 确 定 ",onclick:"popwin.close();",focus:true}];
		popwin.showDialog(2,"上传附件","您所在的用户组没有权限上传附件。",btns,320,130);
	}else{
		popwin.showURL('上传附件','inc/attachment/index.php',600,464);
	}
}

//必须文件名时候触发的事件。
function insertAttachment(fileid, filename){
	Editor.insertAttachment(fileid, filename);
}

function post_PageInit(){
	if(topictype==1){
		E("starttime").onfocus = function(){choosedate.dfd(E('starttime'))};
		E("stoptime").onfocus = function(){choosedate.dfd(E('stoptime'))};
		for(var i=0; i<5; i++){
			addVoteItem();
		}
	}
	if(E("securitycode")){
		E("securitycode").onblur = checkSecurityCode;
	}
}


//view
function view_PageInit(){
	if(E("securitycode")){
		E("securitycode").onblur = checkSecurityCode;
	}
}

